const fs = require('fs');

(()=>{
    // opendirSyncTest()
})()

function opendirSyncTest(){
    let dir = fs.readdirSync(".");
    for (const i in dir) {
        let stats = fs.statSync(dir[i]);
        if (stats.isFile()){
            console.log(dir[i],"file");
        }else if (stats.isDirectory()){
            console.log(dir[i],"dir");
        }
    }
}


function unlinkTest() {
    fs.unlink('./test.txt', (err => {
        if (err) {
            console.log('delete fail');
            //throw err;
        } else {
            console.log('delete ok');
        }
    }));
}

function openTest() {
    fs.open('./message.txt', 'wx', (err, fd) => {
        if (err) {
            if (err.code === 'EEXIST') {
                console.error('message.txt already exists');
                return;
            }
            throw err;
        }
    });
}

function writeFile() {
    fs.writeFile('message.txt', 'Hello Node.js', (err) => {
        if (err) throw err;
        console.log('The file has been saved!');
    });
}

